home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Generic_PatrolAlly.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  6.5 KB  |  220 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. fsm Generic_PatrolAlly : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Generic_PatrolAlly:
  12. //   Follow a path.  Move to attack anything that comes within range,
  13. //   and return to the path when done.
  14. //   Whenever we get within a certain range of a target unit,
  15. //   we follow that unit, and continue to attack any enemies.
  16.  
  17. //------------------------------------------------------------------
  18.  
  19.  
  20.  
  21. //------------------------------------------------------------------
  22. //     Constants
  23. //------------------------------------------------------------------
  24.  
  25.     const
  26.         #include_ <content\ABLScripts\mwconst.abi>
  27.  
  28. //------------------------------------------------------------------
  29. //     Types
  30. //------------------------------------------------------------------
  31.  
  32.     type
  33.         #include_ <content\ABLScripts\mwtype.abi>
  34.     
  35.  
  36. //------------------------------------------------------------------
  37. //     Variables
  38. //------------------------------------------------------------------
  39.  
  40.     var
  41.         static integer            attackRange1;        // At what range do I start shooting?
  42.         static integer            withdrawRange1;        // At what range do I withdraw from combat completely?
  43.         static integer            path;                // What path do I follow?
  44.         static integer            moveType;            // How I move along the path
  45.         static integer            speed;                // The speed at which I move along the path
  46.  
  47.         static ObjectID            whoToJoin;            // Who do I want to join?
  48.         static integer            joinRange;            // At what range do I join my leader?
  49.         static integer            followXOffset;        // My follow X offset
  50.         static integer            followYOffset;        // My follow Y offset
  51.  
  52.         static integer            attackRange2;        // At what range do I start shooting (after joining)?
  53.         static integer            withdrawRange2;        // At what range do I stop shooting (after joining)?
  54.  
  55.         static integer            piloting;            // Piloting skill
  56.         static integer            gunnery;            // Gunnery skill/chance to hit
  57.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  58.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  59.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  60.                                                     // and other things.  It indicates a general level of combat experience.
  61.         static integer            attackThrottle;        // My attack throttle
  62.         static integer            findTypes;            // What kind of enemies to look for
  63.  
  64.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  65.  
  66.         static integer             attackSound;        // The attack sound I play when I first attack
  67.         static integer             deathSound;            // The sound I play when I die
  68.         
  69.         static integer            mood;                // My default mood.
  70.  
  71.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  72.  
  73. //------------------------------------------------------------------
  74. //     Init: my initialization function
  75. //------------------------------------------------------------------
  76.  
  77. function Init;
  78.     code
  79.         // script-specific variables
  80.         attackRange1    = 500;
  81.         withdrawRange1    = attackRange1 * 3 / 2;
  82.         path            = -1;
  83.         moveType        = move_circle;
  84.         speed            = 600;
  85.  
  86.         whoToJoin        = NO_UNIT;
  87.         joinRange        = 500;
  88.         followXOffset    = 0;
  89.         followYOffset    = 50;
  90.  
  91.         attackRange2    = attackRange1;
  92.         withdrawRange2    = attackRange2 * 3 / 2;
  93.  
  94.         takeOffDistance    = 150;
  95.  
  96.         // driver settings
  97.         piloting        = 50;
  98.         gunnery            = 30;
  99.         minDelay        = 1.5;
  100.         maxDelay        = 3.0;
  101.         eliteLevel        = 30;
  102.         attackThrottle    = 80;
  103.         isShotRadius    = 120;
  104.         attackSound        = -1; // no sound
  105.         deathSound        = -1; // no sound
  106.         mood            = NEUTRAL_START;
  107.         findTypes        = FT_DEFAULT;
  108.  
  109. endfunction;
  110.  
  111. //------------------------------------------------------------------
  112. //    StartState: my initial state
  113. //------------------------------------------------------------------
  114.  
  115. state StartState;
  116.  
  117.     code
  118.         SetFiringDelay            (ME,minDelay,maxDelay);
  119.         SetIgnoreFriendlyFire    (ME,true);
  120.         SetIsShotRadius            (ME,isShotRadius);
  121.         SetEntropyMood            (ME,mood);
  122.         SetCurMood                (ME,mood);
  123.         SetSkillLevel            (ME,piloting,gunnery,eliteLevel);
  124.         SetAttackThrottle        (ME,attackThrottle);
  125.     
  126.         if (orderTakeOff(takeOffDistance) == true) then
  127.             trans FollowPathState;
  128.         endif;
  129.  
  130. endstate;
  131.  
  132. //------------------------------------------------------------------
  133. //    FollowPathState: wait for something to shoot
  134. //------------------------------------------------------------------
  135.  
  136. state FollowPathState;
  137.     code
  138.         if (IsWithin(ME,whoToJoin,joinRange)) then
  139.             trans FollowState;
  140.         endif;
  141.  
  142.         if (FindEnemy(attackRange1,findTypes)) then
  143.             trans Attack1State;
  144.         endif;        
  145.  
  146.         if (path <> -1) then
  147.             OrderMoveResumePatrol(path,speed,moveType,true,false);
  148.         else
  149.             OrderMoveLookOut;
  150.         endif;
  151. endstate;
  152.  
  153. //------------------------------------------------------------------
  154. //    Attack1State: look for something to shoot
  155. //------------------------------------------------------------------
  156.  
  157. state Attack1State;
  158.     code
  159.         if (LeaveAttackState(withdrawRange1)) then
  160.             OrderStopAttacking;
  161.             SetTarget(ME,NO_UNIT);
  162.             trans FollowPathState;
  163.         endif;
  164.  
  165.         if (IsWithin(ME,whoToJoin,joinRange)) then
  166.             trans Attack2State;
  167.         endif;
  168.  
  169.         OrderAttack(true);
  170.  
  171. endstate;
  172.  
  173. //------------------------------------------------------------------
  174. //    FollowState: follow the chosen unit
  175. //------------------------------------------------------------------
  176.  
  177. state FollowState;
  178.     code
  179.         if (FindEnemy(attackRange2,findTypes)) then
  180.             trans Attack2State;
  181.         endif;        
  182.  
  183.         OrderMoveFollow(whoToJoin,followXOffset,followYOffset);
  184.  
  185. endstate;
  186.  
  187. //------------------------------------------------------------------
  188. //    Attack2State: look for something to shoot
  189. //------------------------------------------------------------------
  190.  
  191. state Attack2State;
  192.     code
  193.         if (LeaveAttackState(withdrawRange2)) then
  194.             OrderStopAttacking;
  195.             SetTarget(ME,NO_UNIT);
  196.             trans FollowState;
  197.         endif;
  198.  
  199.         OrderAttack(true);
  200.  
  201. endstate;
  202.  
  203. //------------------------------------------------------------------
  204. //    DeadState: OK, I kicked the bucket.
  205. //------------------------------------------------------------------
  206.  
  207. state DeadState;
  208.     code
  209.         if (deathSound <> -1) then    
  210.             PlaySoundOnce(deathSound);
  211.         endif;        
  212.  
  213.         orderDie;
  214.  
  215. endstate;
  216.  
  217.  
  218. endfsm.
  219.  
  220.